home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWTPtrSet.z / RWTPtrSet
Encoding:
Text File  |  1998-10-30  |  20.3 KB  |  529 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTPtrSet<T,C> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tpset.h>
  13.           RWTPtrSet<T,C> s;
  14.  
  15.  
  16.  
  17. SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!!
  18.  
  19.  
  20.  
  21.      RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt requires the Standard C++ Library.
  22.  
  23.  
  24. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  25.      This class maintains a pointer-based collection of values, which are
  26.      ordered according to a comparison object of type CCCC.  Class TTTT is the type
  27.      pointed to by the items in the collection. CCCC must induce a total ordering
  28.      on elements of type TTTT via a public member
  29.  
  30.               bool operator()(const T& x, const T& y)
  31.  
  32.  
  33.  
  34.  
  35.  
  36.      which returns ttttrrrruuuueeee if xxxx should precede yyyy within the collection. The
  37.      structure lllleeeessssssss<<<<TTTT>>>> from the C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an
  38.      example.  Note that items in the collection will be dereferenced before
  39.      being compared.  RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> will not accept an item that compares
  40.      equal to an item already in the collection.  (RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> may
  41.      contain multiple items that compare equal to each other.)  Equality is
  42.      based on the comparison object and not on the ======== operator.  Given a
  43.      comparison object ccccoooommmmpppp, items aaaa and bbbb are equal if
  44.  
  45.                    !comp(a,b) && !comp(b,a).
  46.  
  47.  
  48.  
  49. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  50.  
  51.  
  52.  
  53.      Isomorphic.
  54.  
  55. EEEExxxxaaaammmmpppplllleeeessss
  56.      In this example, a pointer-based set of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs is exercised.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               //
  75.  
  76.  
  77.  
  78.               //tpset.cpp
  79.           //
  80.           #include <rw/tpset.h>
  81.           #include <rw/cstring.h>
  82.           #include <iostream.h>
  83.           #include <function.h>
  84.           main(){
  85.             RWTPtrSet<RWCString, less<RWCString> > set;
  86.             set.insert(new RWCString("one"));
  87.             set.insert(new RWCString("two"));
  88.             set.insert(new RWCString("three"));
  89.             set.insert(new RWCString("one"));  // Rejected: duplicate entry
  90.             cout << set.entries() << endl;   // Prints "3"
  91.             set.clearAndDestroy();
  92.             cout << set.entries() << endl;   // Prints "0"
  93.             return 0;
  94.           }
  95.  
  96. RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss
  97.      Class RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> offers the same interface to a pointer-based
  98.      collection that accepts multiple items that compare equal to each other.
  99.      RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> is a pointer-based collection of key-value pairs.  Class
  100.      sssseeeetttt<<<<TTTT****,,,,rrrrwwww____ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<CCCC,,,,TTTT>>>>,,,,aaaallllllllooooccccaaaattttoooorrrr>>>> is the C++-standard collection
  101.      that serves as the underlying implementation for RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>.
  102.  
  103. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss
  104.               typedef rw_deref_compare<C,T>                  container_comp;
  105.           typedef set<T*, container_comp,allocator>      container_type;
  106.           typedef container_type::size_type              size_type;
  107.           typedef container_type::difference_type        difference_type;
  108.           typedef container_type::iterator               iterator;
  109.           typedef container_type::const_iterator         const_iterator;
  110.           typedef T*                                     value_type;
  111.           typedef T*const&                               reference;
  112.           typedef T*const&                               const_reference;
  113.  
  114.  
  115.  
  116. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  117.               RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const container_comp& comp = container_comp());
  118.  
  119.  
  120.      Constructs an empty set.
  121.  
  122.               RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const RWTPtrSet<T,C>& rws);
  123.  
  124.  
  125.      Copy constructor.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const container_type& s);
  141.  
  142.  
  143.      Creates a pointer based set by copying all elements from s.
  144.  
  145.               RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(T* const* first,T* const* last,const container_comp& comp = container_comp());
  146.  
  147.  
  148.      Constructs a set by copying elements from the array of TTTT****s pointed to by
  149.      ffffiiiirrrrsssstttt, up to, but not including, the element pointed to by llllaaaasssstttt.
  150.  
  151. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss
  152.               RWTPtrSet<T,C>&
  153.           ooooppppeeeerrrraaaattttoooorrrr====(const container_type& s);
  154.           RWTPtrSet<T,C>&
  155.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrSet<T,C>& s);
  156.  
  157.  
  158.      Clears all elements of self and replaces them by copying all elements of
  159.      ssss.
  160.  
  161.               bool
  162.           ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTPtrSet<T,C>& s);
  163.  
  164.  
  165.      Returns ttttrrrruuuueeee if self compares lexicographically less than ssss, otherwise
  166.      returns ffffaaaallllsssseeee.  Items in each collection are dereferenced before being
  167.      compared.  Assumes that type TTTT has well-defined less-than semantics.
  168.  
  169.               bool
  170.           ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrSet<T,C>& s);
  171.  
  172.  
  173.      Returns ttttrrrruuuueeee if self compares equal to ssss, otherwise returns ffffaaaallllsssseeee.  Two
  174.      collections are equal if both have the same number of entries, and
  175.      iterating through both collections produces, in turn, individual elements
  176.      that compare equal to each other.  Elements are dereferenced before being
  177.      compared.
  178.  
  179. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  180.               void
  181.           aaaappppppppllllyyyy(void (*fn)(const T*,void*), void* d) const;
  182.  
  183.  
  184.      Applies the user-defined function pointed to by ffffnnnn to every item in the
  185.      collection.  This function must have prototype:
  186.  
  187.                  void yourfun(const T* a, void* d);
  188.  
  189.  
  190.      Client data may be passed through parameter dddd.
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               iterator
  207.           bbbbeeeeggggiiiinnnn();
  208.           const_iterator
  209.           bbbbeeeeggggiiiinnnn() const;
  210.  
  211.  
  212.      Returns an iterator positioned at the first element of self.
  213.  
  214.               void
  215.           cccclllleeeeaaaarrrr();
  216.  
  217.  
  218.      Clears the collection by removing all items from self.
  219.  
  220.               void
  221.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  222.  
  223.  
  224.      Removes all items from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy
  225.      the objects pointed to by those items.
  226.  
  227.               bool
  228.           ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const;
  229.  
  230.  
  231.      Returns ttttrrrruuuueeee if there exists an element tttt in self that compares equal
  232.      with ****aaaa, otherwise returns ffffaaaallllsssseeee.
  233.  
  234.               bool
  235.           ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const T*,void*), void* d) const;
  236.  
  237.  
  238.      Returns ttttrrrruuuueeee if there exists an element tttt in self such that the
  239.      expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee.  ffffnnnn points to a
  240.      user-defined tester function which must have prototype:
  241.  
  242.                  bool yourTester(const T* a, void* d);
  243.  
  244.  
  245.      Client data may be passed through parameter dddd.
  246.  
  247.               void
  248.           ddddiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrSet<T,C>& s);
  249.  
  250.  
  251.      Sets self to the set-theoretic difference given by ((((sssseeeellllffff ---- ssss)))).  Elements
  252.      from each set are dereferenced before being compared.
  253.  
  254.               iterator
  255.           eeeennnndddd();
  256.           const_iterator
  257.           eeeennnndddd() const;
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.      Returns an iterator positioned "just past" the last element in self.
  273.  
  274.               size_type
  275.           eeeennnnttttrrrriiiieeeessss() const;
  276.  
  277.  
  278.      Returns the number of items in self.
  279.  
  280.               const T*
  281.           ffffiiiinnnndddd(const T* a) const;
  282.  
  283.  
  284.      If there exists an element tttt in self that compares equal with ****aaaa, returns
  285.      tttt.  Otherwise, returns rrrrwwwwnnnniiiillll.
  286.  
  287.               const T*
  288.           ffffiiiinnnndddd(bool (*fn)(const T*,void*), void* d) const;
  289.  
  290.  
  291.      If there exists an element tttt in self such that the expression
  292.      ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, returns tttt.  Otherwise, returns rrrrwwwwnnnniiiillll.  ffffnnnn points to
  293.      a user-defined tester function which must have prototype:
  294.  
  295.                  bool yourTester(const T* a, void* d);
  296.  
  297.  
  298.      Client data may be passed through parameter dddd....
  299.  
  300.               bool
  301.           iiiinnnnsssseeeerrrrtttt(T* a);
  302.  
  303.  
  304.      Adds the item aaaa to the collection.  Returns ttttrrrruuuueeee if the insertion is
  305.      successful, otherwise returns ffffaaaallllsssseeee.  The function will return ttttrrrruuuueeee
  306.      unless the collection already holds an element with an equivalent key.
  307.  
  308.               void
  309.           iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const RWTPtrSet<T,C>& s);
  310.  
  311.  
  312.      Sets self to the intersection of self and ssss.  Elements from each set are
  313.      dereferenced before being compared.
  314.  
  315.               bool
  316.           iiiissssEEEEmmmmppppttttyyyy() const;
  317.  
  318.  
  319.      Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise.
  320.  
  321.               bool
  322.           iiiissssEEEEqqqquuuuiiiivvvvaaaalllleeeennnntttt(const RWTPtrSet<T,C>& s) const;
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.      Returns ttttrrrruuuueeee if there is set equivalence between self and ssss, and returns
  339.      ffffaaaallllsssseeee otherwise.
  340.  
  341.               bool
  342.           iiiissssPPPPrrrrooooppppeeeerrrrSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrSet<T,C>& s) const;
  343.  
  344.  
  345.      Returns ttttrrrruuuueeee if self is a proper subset of ssss, and returns  ffffaaaallllsssseeee
  346.      otherwise.
  347.  
  348.               bool
  349.           iiiissssSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrSet<T,C>& s) const;
  350.  
  351.  
  352.      Returns ttttrrrruuuueeee if self is a subset of ssss or if self is set equivalent to ssss,
  353.      ffffaaaallllsssseeee otherwise.
  354.  
  355.               size_type
  356.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const;
  357.  
  358.  
  359.      Returns the number of elements tttt in self that compare equal with ****aaaa.
  360.  
  361.               size_type
  362.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(T*,void*), void* d);
  363.           size_type
  364.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(const T*,void*), void* d) const;
  365.  
  366.  
  367.      Returns the number of elements tttt in self such that the expression
  368.      ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee.   ffffnnnn points to a user-defined tester function which
  369.      must have prototype:
  370.  
  371.                  bool yourTester(const T* a, void* d);
  372.  
  373.  
  374.      Client data may be passed through parameter dddd.
  375.  
  376.               T*
  377.           rrrreeeemmmmoooovvvveeee(const T* a);
  378.  
  379.  
  380.      Removes and returns the first element tttt in self that compares equal with
  381.      ****aaaa.  Returns rrrrwwwwnnnniiiillll if there is no such element.
  382.  
  383.               T*
  384.           rrrreeeemmmmoooovvvveeee(bool (*fn)(const T*,void*), void* d);
  385.  
  386.  
  387.      Removes and returns the first element tttt in self such that the expression
  388.      ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee.  Returns rrrrwwwwnnnniiiillll if there is no such element.  ffffnnnn
  389.      points to a user-defined tester function which must have prototype:
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.                  bool yourTester(const T* a, void* d);
  405.  
  406.  
  407.      Client data may be passed through par_meter dddd.
  408.  
  409.               size_type
  410.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a);
  411.  
  412.  
  413.      Removes all elements tttt in self that compares equal with ****aaaa.  Returns the
  414.      number of items removed.
  415.  
  416.               size_type
  417.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const T*,void*), void* d);
  418.  
  419.  
  420.      Removes all elements tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))is
  421.      ttttrrrruuuueeee.  Returns the number of items removed.  ffffnnnn points to a user-defined
  422.      tester function which must have prototype:
  423.  
  424.                  bool yourTester(const T* a, void* d);
  425.  
  426.  
  427.      Client data may be passed through parameter dddd.
  428.  
  429.               set<T*, container_comp,allocator>&
  430.           ssssttttdddd();
  431.           const set<T*, container_comp,allocator>&
  432.           ssssttttdddd() const;
  433.  
  434.  
  435.      Returns a reference to the underlying C++-standard collection that serves
  436.      as the implementation for self.
  437.  
  438.               void
  439.           ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrSet<T,C>& s);
  440.  
  441.  
  442.      Sets self to the symmetric difference of self and ssss.  Elements from each
  443.      set are dereferenced before being compared.
  444.  
  445.               void
  446.           UUUUnnnniiiioooonnnn(const RWTPtrSet<T,C>& s);
  447.  
  448.  
  449.      Sets self to the union of self and ssss.  Elements from each set are
  450.      dereferenced before being compared. Note the uppercase "U" in UUUUnnnniiiioooonnnn to
  451.      avoid conflict with the C++ reserved word.
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt((((3333CCCC++++++++))))
  467.  
  468.  
  469.  
  470. Related Global Operators
  471.               RWvostream&
  472.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrSet<T,C>& coll);
  473.           RWFile&
  474.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrSet<T,C>& coll);
  475.  
  476.  
  477.      Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to
  478.      it if it has already been saved.
  479.  
  480.               RWvistream&
  481.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSet<T,C>& coll);
  482.           RWFile&
  483.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSet<T,C>& coll);
  484.  
  485.  
  486.      Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm.
  487.  
  488.               RWvistream&
  489.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSet<T,C>*& p);
  490.           RWFile&
  491.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSet<T,C>*& p);
  492.  
  493.  
  494.      Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a
  495.      new collection off the heap and sets pppp to point to it, or sets pppp to point
  496.      to a previously read instance.  If a collection is created off the heap,
  497.      then you are responsible for deleting it.
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.